package com.ice.framework.extend

import android.content.Context
import android.util.Log
import android.view.View
import android.widget.ImageView
import androidx.appcompat.widget.AppCompatImageView
import com.bumptech.glide.Glide
import com.bumptech.glide.request.RequestOptions
import com.ice.framework.utils.GlideBlurformation
import java.text.SimpleDateFormat
import java.util.*

fun ImageView.load(context:Context,url:String){
    Glide.with(context).load(url).into(this)
}
fun AppCompatImageView.load(context:Context, url:String){
    Glide.with(context).load(url).into(this)
}

fun ImageView.loadBlur(context:Context, url:String){
    Glide.with(context).load(url)
            .apply(RequestOptions.bitmapTransform(GlideBlurformation(context)))
            .into(this)
}

fun Date.format(format:String):String{
    return SimpleDateFormat(format, Locale.CHINA).format(this)
}

fun String.toDate(format:String):Date{
    return SimpleDateFormat(format, Locale.CHINA).parse(this)
}

const val MIN_ClICK_DELAY_TIME=1000
var lastClickTime=0L
var lastClickView:View?=null

fun View.setOnNotDoubleClickListener(block:(v:View)->Unit){
    this.setOnClickListener {
        val currentTime=Calendar.getInstance().timeInMillis
        if(lastClickView==null|| lastClickView!=this||currentTime- lastClickTime> MIN_ClICK_DELAY_TIME){
            lastClickTime=currentTime
            lastClickView=this
            block(it)
        }else{
            Log.w("OnNotDoubleClick","点击过快")
        }
    }
}


